﻿<?php
/**
 *
 * @author Duminda Dharmakeerthi
 *
 */
class contact{
	private $id;
	private $studentId;
	private $contactType;
	private $address;
	private $landPhone;
	private $mobilePhone;
	private $email;
	private $fax;

	function __construct(){
	}

	/**
	 * Fill contact information and create a contact object.
	 *
	 * @param $address
	 * @param $landPhone
	 * @param $mobilePhone
	 * @param $email
	 * @param $fax
	 * @return contact object with the given contact information
	 */
	public static function fillContact($studentId, $contactType, $address, $landPhone, $mobilePhone, $email, $fax){
		$C = new self();
		$C->setContact($studentId, $contactType, $address, $landPhone, $mobilePhone, $email, $fax);
		return $C;
	}

	/**
	 * Set the contact values.
	 *
	 * @param $address
	 * @param $landPhone
	 * @param $mobilePhone
	 * @param $email
	 * @param $fax
	 */
	protected function setContact($studentId, $contactType, $address, $landPhone, $mobilePhone, $email, $fax){
		$this->studentId = $studentId;
		$this->contactType = $contactType;
		$this->address = $address;
		$this->landPhone = $landPhone;
		$this->mobilePhone = $mobilePhone;
		$this->email = $email;
		$this->fax = $fax;
	}

	/**
	 * Adding a contact.
	 *
	 * @return Id of the added contact or '0' if an error occured.
	 */
	public function addContact(){
		$addContactQuery = "INSERT INTO contacts (
								studentId, 
								contactType, 
								address, 
								landPhone, 
								mobilePhone, 
								email, 
								fax
							) VALUES (
								'$this->studentId', 
								'$this->contactType', 
								'$this->address',
								'$this->landPhone',
								'$this->mobilePhone',
								'$this->email',
								'$this->fax'
							)";
		if(mysql_query($addContactQuery)){
			return mysql_insert_id();
		}else{
			return 0;
		}
	}

	/**
	 * Updating a contact.
	 *
	 * @param $contactId
	 * @return TRUE if query successful. FALSE otherwise.
	 */
	public function updateContact($contactId){
		include_once '../dbconnection.php';
		$updateContactQuery = "UPDATE contacts SET address='$this->address', landPhone='$this->landPhone', mobilePhone='$this->mobilePhone', email='$this->email', fax='$this->fax' WHERE contactId='$contactId'";
		return mysql_query($updateContactQuery);
	}

	public function deleteContact($contactId){
		include_once '../dbconnection.php';
		$deleteContactQuery = "";
		return mysql_query($deleteContactQuery);
	}
	
	
}
?>